//
//  UIInteractionControl.swift
//  DemoUI
//
//  Created by 白瑾浩 on 2022/1/7.
//

import Foundation
import UIKit
//ui逻辑交互 slider
class UIInteractionViewControl:UIViewController{
    var anmation:UIView?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        
        //slider基本使用
        let slider = UISlider(frame: CGRect(x: 0, y: 100, width: 300, height: 30))
        //最大值
        slider.maximumValue = 100
        //最小值
        slider.minimumValue = 0
        //设置当前值
        slider.value = 5
        //滑到最小值进度条颜色
        slider.minimumTrackTintColor = UIColor.red
        //滑到最大值进度条颜色
        slider.maximumTrackTintColor = UIColor.blue
        //设置滑块的颜色
        slider.thumbTintColor = UIColor.green
        self.view.addSubview( slider )
        
        //自定义外观 uislider
        let slider1 = UISlider(frame: CGRect(x: 0, y: 140, width: 300, height: 30))
        slider1.maximumValue = 100
        slider1.minimumValue = 0
        slider1.value = 5
        //图片代替颜色  button bird2 bird2 是assets中图片的名称
        slider1.setThumbImage(UIImage(named: "button"), for: UIControl.State.normal)
        slider1.setMinimumTrackImage(UIImage(named: "bird2"), for: UIControl.State.normal)
        slider1.setMaximumTrackImage(UIImage(named: "bird2"), for: UIControl.State.normal)
        //拖动结束才触发
        slider1.isContinuous = false //连续打印值  false 拖动结束才打印  true拖动连续打印
        //值改变调用
        slider1.addTarget(self, action: #selector(change), for: UIControl.Event.valueChanged)
        self.view.addSubview( slider1 )
        
        let mUILabel = UILabel()
        mUILabel.frame =  CGRect(x: 0, y: 200, width: 300, height: 30)
        mUILabel.text = "当前值：--"
        mUILabel.textColor = UIColor.red
        mUILabel.tag = 10000
        view.addSubview( mUILabel )
        
        anmation = UIView(frame: CGRect(x: 10, y: 250, width: 300, height: 300))
        anmation?.backgroundColor = .blue
        view.addSubview( anmation! )
        
        
        
        
        
        
        
    }
    @objc func change(_ slider:UISlider ){
        print("当前值：", slider.value )
        let mUILabel = self.view.viewWithTag( 10000 )
        guard  mUILabel is UILabel  else{
            return
        }
        (mUILabel as! UILabel).text = "当前值：\(slider.value)"
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        UIView.transition(with: anmation!,  duration: 2, options: UIView.AnimationOptions.transitionCurlUp) {
               //这里进行视图内容的更换
        }
    }
}
